package com.kara.woodAgent.agent.wood;

import com.kara.woodAgent.agent.graph.BaseGraph;
import com.kara.woodAgent.agent.wood.context.WoodContext;
import com.kara.woodAgent.agent.wood.model.SpecialAgentInfo;
import com.kara.woodAgent.agent.wood.model.SpecialAgentWrapper;
import com.kara.woodAgent.agent.wood.node.DispatchNode;
import com.kara.woodAgent.agent.wood.node.FacadeNode;
import com.kara.woodAgent.agent.wood.node.PlanningNode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author tzy
 * @version 1.0
 * @project wood_agent
 * @description todo
 * @date 2025/6/9 11:03:39
 */
@Configuration
public class WoodAgentConfig {

    /**
     * agent 架构
     * <p>
     * planning   ------> dispatch ----> execution <br/>
     * replanning <-error-         <----
     */

    @Bean("facade")
    public FacadeNode facadeNode(List<SpecialAgentWrapper> specialAgentWrappers) {
        List<SpecialAgentInfo> specialAgentInfos = specialAgentWrappers.stream().map(SpecialAgentWrapper::toSpecialAgentInfo).toList();
        return new FacadeNode(specialAgentInfos);
    }

    @Bean("planning")
    public PlanningNode planningNode(List<SpecialAgentWrapper> specialAgentWrappers) {
        List<SpecialAgentInfo> specialAgentInfos = specialAgentWrappers.stream().map(SpecialAgentWrapper::toSpecialAgentInfo).toList();
        return new PlanningNode(specialAgentInfos);
    }

    @Bean("dispatch")
    public DispatchNode dispatchNode() {
        return new DispatchNode();
    }

    @Bean("woodAgent")
    public BaseGraph<WoodContext> createAgent(List<SpecialAgentWrapper> specialAgentWrappers,
                                              FacadeNode facadeNode,
                                              PlanningNode planningNode,
                                              DispatchNode dispatchNode) {

        BaseGraph<WoodContext> woodAgent = new BaseGraph<WoodContext>()
                .addStartNode("facade", facadeNode)
                .addNode("planning", planningNode)
                .addNode("dispatch", dispatchNode);

        for (SpecialAgentWrapper wrapper : specialAgentWrappers) {
            woodAgent.addNode(wrapper.getAgentName(), wrapper.getGraph());
        }

        return woodAgent;
    }



}
